import * as fs from 'fs';
import * as yaml from 'js-yaml';
import * as _ from 'lodash';
import { join } from 'path';

const YAML_CONFIG_FILENAME = 'config.yml';

const YAML_CONFIG_NODE_ENV = `config.${
  process.env.NODE_ENV === 'production' ? 'production' : 'development'
}.yml`;

const config = yaml.load(
  fs.readFileSync(join('config', YAML_CONFIG_NODE_ENV), 'utf8'),
);

const envConfig = yaml.load(
  fs.readFileSync(join('config', YAML_CONFIG_FILENAME), 'utf8'),
);

export default () => {
  return _.merge(config, envConfig);
};
